
#include "APP.h"


/* USER CODE BEGIN EFP */
Motor_DCBRUSH_MOTOR *motor1 ;
Motor_DCBRUSH_MOTOR *motor2 ;
Encoder_AB *Motor_Encoder1;
PID_count *PosionPID;
/* USER CODE END EFP */


void _DCBRUSH_MOTOR1_INITIALIZED()
{	
	motor1=create_Motor_DCBRUSH_MOTOR(1);
	motor1->pwm1_channel = TIM_CHANNEL_1;
	motor1->pwm1_timer = &htim3;
	motor1->pwm2_channel = TIM_CHANNEL_2;
	motor1->pwm2_timer = &htim3;
	motor1->pwm_arr = motor1->pwm1_timer->Init.Period ;
	_DCBRUSH_MOTOR_INITIALIZED(motor1);			
}

void _AB_ENCODER_INITIALIZED()
{
	Motor_Encoder1 = create_Encoder_AB(1);
	Motor_Encoder1->encoder_timer=&htim1;
	Motor_Encoder1->Const_ARR = Motor_Encoder1->encoder_timer->Init.Period;
	Motor_Encoder1->totalCount = 0;
	Motor_Encoder1->lastCount = 0;
	Motor_Encoder1->encoder_value = 0;
	Motor_Encoder1->overflowNum  = 0;
	Motor_Encoder1->Count  = 0;
	Motor_Encoder1->Const_Line_one_round = 334;
	Motor_Encoder1->EncoderMode = 4;
	Motor_Encoder1->IO_A_port = GPIOA;
	Motor_Encoder1->IO_A_pin = GPIO_PIN_8;
	Motor_Encoder1->IO_B_port = GPIOA;
	Motor_Encoder1->IO_B_pin = GPIO_PIN_9;
	MOTOR_Encoder_INITIALIZED(Motor_Encoder1);
	__HAL_TIM_SET_COUNTER(Motor_Encoder1->encoder_timer, 0);
}

void PID_INITIALIZED()
{
	PosionPID = create_PID_COUNT_VALUE(1);
	PosionPID->want_count=1000;				 
	PosionPID->output_val=0.0;
	PosionPID->Error=0.0;
	PosionPID->LastError=0.0;
	PosionPID->integral=0.0;
	PosionPID->Kp = 80;
	PosionPID->Ki = 0;
	PosionPID->Kd = 15;

}



void APP_INITIALIZED()
{
	motor1=create_Motor_DCBRUSH_MOTOR(1);
	Motor_Encoder1 = create_Encoder_AB(1);
	PosionPID = create_PID_COUNT_VALUE(1);
	base_timer = htim4;
	_DCBRUSH_MOTOR1_INITIALIZED();	
	_AB_ENCODER_INITIALIZED();
	PID_INITIALIZED();
}
